package cn.xhc.common.util;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;

import com.alibaba.fastjson.JSONObject;

import cn.xhc.question.service.IQuestionSpiderService;

/**
 * 多线程实现采集数据
 * @author Administrator
 *
 */
public class MutilThreadUtil implements Callable<Object>{
	/*线程名*/
	private String name;
	/*参数*/
	private Map<String, Object> paramsMap = new HashMap<String, Object>();
	public MutilThreadUtil() {
	}
	public MutilThreadUtil(String name) {
		super();
		this.name = name;
	}

	@Override
	public Object call() throws Exception {
		JSONObject resultJson = new JSONObject();
		String operType = paramsMap.get("operType")+"";
		if("spiderColumn".equalsIgnoreCase(operType)){
			/*为指定栏目采集数据*/
			resultJson = this.spiderColumn(paramsMap);
		}
		return resultJson;
	}
	/**
	 * 采集某个栏目
	 * @param paramsMap
	 * @return
	 */
	private JSONObject spiderColumn(Map<String, Object> paramsMap) {
		String url = paramsMap.get("url")+"";
		IQuestionSpiderService questionSpiderService = 
				(IQuestionSpiderService) paramsMap.get("questionSpiderService");
		return questionSpiderService.saveBatchItemsService(url);
		
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Map<String, Object> getParamsMap() {
		return paramsMap;
	}

	public void setParamsMap(Map<String, Object> paramsMap) {
		this.paramsMap = paramsMap;
	}

	
	
	
	
}
